filetree = {
	getFileTree: function(rootdir) {
		var isWindows = utils.isWindows();
		
		var folderChar = "/";
		if (isWindows == false)
			folderChar = ":";
		
		if (isWindows == true)
			rootdir = rootdir.replace("\\\\", "c:\\");
		
		//alert("Windows? " + isWindows + " \n" + rootdir);	
		var folders = [];

		var rootinfo  = DWfile.listFolder(rootdir, "directories");
		var dirHistory = {};
		
		folders[folders.length] = filetree.createFolderObject(rootdir);
		folders[0].mapped = true;
		dirHistory[folders[0].path] = true;
		for (var i = 0; i < rootinfo.length; i++) {
			if (rootinfo[i] != "Templates" && rootinfo[i] != "_notes") {
				folders[folders.length] = filetree.createFolderObject(rootdir+rootinfo[i]+folderChar);
				dirHistory[rootdir+rootinfo[i]+folderChar] = true;
			}
		}

		var foundOne = true;
		while (foundOne == true) {
			foundOne = false;
			var fLength = folders.length;
			for (var i = 1; i < fLength; i++) {
				if (folders[i].mapped == false) {
					folders[i].mapped = true;
					//alert("Looking in " + folders[i].path + "\n\n" + DWfile.listFolder(folders[i].path, "directories") );
					var dirs  = DWfile.listFolder(folders[i].path, "directories");
					for (var v = 0; v < dirs.length; v++) {
						var foldername = folders[i].path+dirs[v]+folderChar;
						if (typeof(dirs[v]) != "undefined" && dirs[v] != "undefined" && !dirHistory[foldername] && dirs[v] != "Templates" && dirs[v] != "_notes") {		
							folders[folders.length] = filetree.createFolderObject(foldername);
							//alert("adding\n" + folders[i].path+dirs[v]+folderChar + "\n\n" + dirHistory[dirs[v]]);	
							dirHistory[foldername] = true;
							foundOne = true;
						}
					}
				}
			}
		}

		// finally, now we create a list of files!
		var files = [];
		
		for (var i = 0; i < folders.length; i++) {
			var flist = DWfile.listFolder(folders[i].path, "files");
			for (var v = 0; v < flist.length; v++) {
				files[files.length] = folders[i].path.replace("c:", "")+flist[v];
			}
		}
		
		return files;
	},
	createFolderObject: function(fpath) {
		return {path:fpath, mapped:false};
	},
	fileIsValidForTesting: function(fpath) {
		var res = false;
		var contents = DWfile.read(fpath);
		if (contents.indexOf("</BODY")>-1 || contents.indexOf("</body")>-1 || contents.indexOf("</Body")>-1)
			res = true;
		return res;
	}
}